package com.zhengxin.web;

import java.util.List;

import com.zhengxin.pojo.Department;
import com.zhengxin.pojo.Employee;

/**
 * 员工模块 1、先进入添加员工的页面 2、列表展示 3、添加员工信息
 */
public class EmployeeAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Employee employee;

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@Override
	public String execute() throws Exception {
		return super.execute();
	}

	// 列表展示方法
	public String list() {
		// 查询所有的员工信息
		List<Employee> listEmp = employeeService.getAll();
		// 保存
		request.put("listEmp", listEmp);
		return "list";
	}

	// 保存
	public String save() {
		employeeService.save(employee);
		return "edit";
	}

	// 1、先进入添加员工的页面
	public String viewEdit() {
		/******* 判断是否进入添加页面或者是修改页面 **********/
		// 如果是修改的话首先根据id主键查询出所有的信息
		if (employee != null && employee.getId() != null) {
			this.employee=employeeService.findByid(employee.getId());
		}
		// 查询所有的部门
		List<Department> listDept = departmentService.getAll();
		// 保存
		request.put("listDept", listDept);
		// 跳转到添加部门的页面
		return "viewEdit";
	}

	// 删除员工
	public String delete() {
		employeeService.delete(employee.getId());
		return list();
	}

	// 编辑修改
	public String update() {
		employeeService.update(employee);
		return "edit";
	}

	//查询
	public String find(){
		Employee listEmp=employeeService.findByid(employee.getId());
		request.put("listEmp", listEmp);
		return "find";
	}
}
